package ar.com.ford.it.fullEconomics.view.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class InterfaceBMRuncheeAction extends Action {
	
	// Agregado por LSPARACI
	public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
	
             
    {
      /* try {
          System.out.println("Ejecutando InterfazBMRuncheeAction.Execute...");
       } catch(Exception e) {e.printStackTrace();
	      System.out.println("Fallo la ejecucion de InterfazBMRuncheeAction.Execute");
       }
    
        LogProcessLogic logProcess = new LogProcessLogic();

        //FullEconomicsWslxUser user = (FullEconomicsWslxUser) webSession
        //        .getUser();
        //String userId = user.getId();
       */ String userId = "p_hcode";
       /* 
        try {
           String borrar = RequestContext.getLocalInstance().getUserId();
           if (borrar != null) {
        	   userId = borrar;
           }
        } catch(Exception e) {e.printStackTrace();
        System.out.println("No se pudo acceder al request.getUserPrincipal().getName()");
        }
        
    	HttpSession session = request.getSession();

    	session.setAttribute("p_usr_cds", userId);
		
        // Agregado LSPARACI
        request.getSession().getServletContext().getRealPath(request.getContextPath());
        ReadFile parser;
        Teesx03Intflog intflog = null;

        
        try {
            //Timestamp generationDate = new Timestamp(0);
            Teesx01Intfsource intfSource = new Teesx01Intfsource();
            intfSource.setEesx01IntfIdNumberK(2);
            Teesx02Fileconten fileConten = logProcess.getFileContent(intfSource);
            
            // LSPARACI
            parser = new ReadFile(fileConten);
 
            // aca seguiria el codigo original
            
            InterfaceProccesFile inStrategy = (InterfaceProccesFile) new UsageStrategy();
            Teesx03Intflog lastIntfLog = logProcess.getLastIntfLog(fileConten
                    .getEesx01Intfsource());
            if (lastIntfLog != null
                    && lastIntfLog.getEesx03IlogProcStatusCodeC()
                            .equalsIgnoreCase("R")) {
                long diffInHours = FullEconomicsDateUtil.getDifferenceInHours(
                        lastIntfLog.getEesx03IlogStartM(), new Timestamp(System
                                .currentTimeMillis()));
                // si es mayor a 6 horas, lo cierro y abro el nuevo
                if (diffInHours > 6) {
                    logProcess
                            .insertLogIntfLevent(
                                    userId,
                                    lastIntfLog,
                                    "E",
                                    "Se cancelo el proceso, tiempo de corrida mayor a 6 horas",
                                    0);
                    logProcess.updateLogInfo(lastIntfLog, "C", new Timestamp(
                            System.currentTimeMillis()));
                    // Status Proces Runin
                    intflog = logProcess.insertLogInf(fileConten, userId, "R",
                            new Timestamp(System.currentTimeMillis()));
                    if(intflog==null ||userId==null)
                       System.out.println("Intenta parsear un null");
                    
   // LSPARACI PARA TEST - SINO NO PROCESA                 parser.processLineByLine(inStrategy, intflog, userId);
                    logProcess.updateLogInfo(intflog, "S", new Timestamp(System
                            .currentTimeMillis()));
                    System.out.println("codigo de salida 200");
                    response.setStatus(200);
                }else{
                	System.out.println("codigo de salida 501");
                	response.setStatus(501);
                    
                }
            } else {
                // Status Proces Runin
                intflog = logProcess.insertLogInf(fileConten, userId, "R",
                        new Timestamp(System.currentTimeMillis()));
                parser.processLineByLine(inStrategy, intflog, userId);
                logProcess.updateLogInfo(intflog, "S", new Timestamp(System
                        .currentTimeMillis()));
                response.setStatus(200);
            }
            
        } catch (FullEconomicsException e) {
            logProcess.updateLogInfo(intflog, "C", new Timestamp(System
                    .currentTimeMillis()));
        	System.out.println("codigo de salida 502");
        	System.out.println("porque seguro esto es null" );
        	System.out.println("intflog"+intflog );
        	System.out.println("userId");
            response.setStatus(502);
        } 
      
        
       */
        //return null;
       return mapping.findForward("success");
    }
}
